package com.ward.thread;

/**
 * Created by ward on 2017-08-25.
 */
public class TestYield {

    public static void main(String[] args){
       /* MyThread3 t1=new MyThread3("t1");
        MyThread3 t2=new MyThread3("t2");
        t1.start();
        t2.start();*/
       Thread t3=new Thread(new MyThread4(),"t3");
        Thread t4=new Thread(new MyThread4(),"t3");
       t3.start();
       t4.start();
    }
}
class  MyThread3 extends Thread{
    MyThread3(String s){
        super(s);
    }

    public void run(){
        for (int i=1;i<=20;i++){
            System.out.println(getName()+"--"+i);
            if((i%10)==0){
                System.out.println("=-----------------");
                yield();
            }

        }
    }
}

class MyThread4 implements  Runnable{


    @Override
    public void  run(){
        for (int i=1;i<=20;i++){
            System.out.println(Thread.currentThread().getName()+"--"+i);
            if((i%10)==0){
                System.out.println("=-----------------");
                Thread.yield();
            }

        }
    }
}
